package com.own.business.question.entity.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.own.business.question.entity.po.Question;
import com.own.component.common.base.entity.vo.BaseVo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.List;

/**
 * QuestionVo
 *
 * @author 陈学礼 （你是一段成熟的代码，要学会自己改bug）
 * @version 4.0.0
 * @date 2021/05/14 09:41:05
 * @since 4.0.0
 */
@Schema(description = "题目" + ConstantBeanSuffix.VO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class QuestionVo extends BaseVo<Question> {

    @Schema(description = "题目类型 1=单选 2=多选 3=判断 4=填空 5=简答")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer type;

    @Schema(description = "难度 1=入门 2=一般 3=优秀 4=一般面试 5=大企业面试")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer difficulty;

    @Schema(description = "权重 0-9")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer weight;

    @Schema(description = "是否不可用 1=不可用 0=可用")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer disabled;

    @Schema(description = "题干")
    private String name;

    @Schema(description = "题干的图片")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String nameImage;

    @Schema(description = "判断题，填空题，简答题答案类型答案为json列表数据")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String answer;

    @Schema(description = "用户的答案数据，判断题，填空题，简答题答案类型答案为json列表数据")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String userAnswer;

    @Schema(description = "判定分数")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal judging;

    @Schema(description = "简单讲解")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String explainSimple;

    @Schema(description = "详细讲解")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String explainDetail;

    @Schema(description = "总获取到的数量")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer total;

    @Schema(description = "正确率")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private BigDecimal rightProbability;

    @Schema(description = "选项列表")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private List<QuestionOptionVo> optionList;

    @Schema(description = "打乱之后的选项顺序")
    @JsonIgnore
    private String keySortOrder;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public QuestionVo(@NonNull Question entity) {
        super(entity);
        this.type = entity.getType();
        this.difficulty = entity.getDifficulty();
        this.weight = entity.getWeight();
        this.disabled = entity.getDisabled();
        this.name = entity.getName();
        this.nameImage = entity.getNameImage();
        this.answer = entity.getAnswer();
        this.explainSimple = entity.getExplainSimple();
        this.explainDetail = entity.getExplainDetail();
        this.total = entity.getTotal();
        this.rightProbability = entity.getRightProbability();
    }

    /**
     * 转po对象
     *
     * @param entity 原
     * @return po对象
     */
    @Override
    public Question toPo(Question entity) {
        if (entity == null) {
            entity = new Question();
        }
        entity.setType(this.type);
        entity.setDifficulty(this.difficulty);
        entity.setWeight(this.weight);
        entity.setDisabled(this.disabled);
        entity.setName(this.name);
        entity.setNameImage(this.nameImage);
        entity.setAnswer(this.answer);
        entity.setExplainSimple(this.explainSimple);
        entity.setExplainDetail(this.explainDetail);
        entity.setTotal(this.total);
        entity.setRightProbability(this.rightProbability);
        return super.toPo(entity);
    }


}
